var top_scroll = new Swiper('.swiper-container', {
  loop: true,
  pagination: '.swiper-pagination',
  autoplay: 4000
});
var scms = new Swiper('.scroll-ms', {
  slidesPerView: 3.3,
  roundLengths: true,
  onReachEnd: function() { // move to last slide
      window.location.href = "http://m.jianke.com/zhuanti/qianggou2/";
    }
    //autoplay:4000     
});
var jk_ads = new Swiper('.jk-ads', {
  loop: true,
  pagination: '.swiper-pagination',
  autoplay: 4000
});
var login;
//Countdown
function Countdown() {
  var show_time = document.getElementById("seckill_time"); //show time
  var show_H = document.getElementById("H");
  var show_h = document.getElementById("h");
  var show_M = document.getElementById("M");
  var show_m = document.getElementById("m");
  var show_D = document.getElementById("D");
  var show_d = document.getElementById("d");
  today = new Date();
  today.setHours(0);
  today.setMinutes(0);
  today.setSeconds(0);
  today.setMilliseconds(0);
  var tomorrow_0 = today.getTime() / 1000 + (24 * 3600);
  var current_time = Math.round(new Date().getTime() / 1000)
  var expire = tomorrow_0 - current_time;
  window.setTimeout(Countdown, 1000);
  var this_H = parseInt(expire / 3600);
  show_H.innerText = parseInt(this_H / 10);
  show_h.innerText = parseInt(this_H % 10);
  show_M.innerText = parseInt((expire - this_H * 3600) / 60 / 10);
  show_m.innerText = parseInt((expire - this_H * 3600) / 60 % 10);
  show_D.innerText = parseInt(parseInt((expire - this_H * 3600) % 60 / 10))
  show_d.innerText = parseInt(parseInt((expire - this_H * 3600) % 60 % 10))
}
Countdown();

function openkf() {
  var ref = document.referrer;
  window.open("http://kf.jianke.com/LR/Chatpre.aspx?id=PFB31671888&lng=cn&r=" + ref + "&p=" + window.location.toString());
}
var Load = {
  init: function() {
    var self = this;
    var bottom = $(".jk-footer");
    i = 0
    for (var j = 0; j <= 9; j++) {
      self.scollMove(bottom);
    }
  },
  loadMore: function(mdata) {
    var list = $(".jk-m-list");
    var loadStr = "";
    if (mdata.length > 0 && i <= 29) {
            for (var j = 0; j <= 9; j++) {  
      loadStr += '<li class="jk-m-item"><a href="http://m.jianke.com/product/' + mdata[i].imgid + '.html">' +
        '<img src="http://img.jianke.net/jk2016/mjianke/m/images/pro-grey.jpg" data-original="http://img.jianke.net/jk2016/mjianke/m/images/pro/' + mdata[i].imgid + '.jpg" alt=' + mdata[i].name + '>' +
        '<div class="love-item-title"><span class="love-item-tit">' + mdata[i].name + '</span><span class="love-item-dsc">' + mdata[i].title + '</span>' +
        '<span class="love-item-price">' + mdata[i].price + '</span></div></a></li>';
      i += 1;
    }
    }
    list.append(loadStr);
    $('img').picLazyLoad();
  },
  scollMove: function(footer) {
    var self = this;
    var mlist = $(".jk-m-list");
    var defTop = 10;
    $(window).on("scroll resize", function() {
      var docHeight = $(document).height() - footer.height()
      var scollHeight = $(window).scrollTop() + $(window).height();
      $(".all-item").height($(".scroll-ms").height())
      if (scollHeight >= docHeight) {
        if ($(window).scrollTop() > defTop && i <= 29) {
          defTop = $(window).scrollTop();
          var listpro = {
            "mlist": [{
                "imgid": "24075",
                "name": "枸地氯雷他定片(贝雪)",
                "title": "慢性荨麻疹、过敏性鼻炎。",
                "price": "&yen;78"
              }, {
                "imgid": "11692",
                "name": "肾宝片（汇仁）",
                "title": "调和阴阳，温阳补肾，扶正固本。用于腰腿酸痛，精神不振，夜尿频多，畏寒怕冷，妇女白带清稀。",
                "price": "&yen;322"
              }, {
                "imgid": "514234",
                "name": "枸橼酸西地那非片(金戈)",
                "title": "适用于治疗勃起功能障碍",
                "price": "&yen;670"
              }, {
                "imgid": "757947",
                "name": "枸杞子 选粒(280粒)",
                "title": "养肝；滋肾；润肺。",
                "price": "&yen;23"
              }, {
               "imgid": "734363",
                "name": "大枣 特选粒",
                "title": "红枣味甘性温、归脾胃经，有补中益气、养血安神、缓和药性的功能。",
                "price": "&yen;36"
              }, {
                "imgid": "11917",
                "name": "屈螺酮炔雌醇片(优思明)",
                "title": "安全高效避孕。",
                "price": "&yen;105"
              }, {
                "imgid": "11101",
                "name": "奥利司他胶囊(艾丽)",
                "title": "OTC瘦身，拍4发7。",
                "price": "&yen;175"
              }, {
                "imgid": "52836",
                "name": "龟龄集",
                "title": "第二件半价，第三件3折&nbsp;&nbsp;强身补脑，固肾补气。",
                "price": "&yen;480"
              }, {
                "imgid": "220786",
                "name": "替格瑞洛片(倍林达)",
                "title": "本品用于急性冠脉综合征(不稳定性心绞痛、非ST段抬高心肌梗死或ST段抬高心肌梗死)患者，包括接受药物治疗和经皮冠状动脉介入(PCI)治疗的患者，降低血栓性心血管事件的发生率。",
                "price": "&yen;163"
              }, {
                "imgid": "76870",
                "name": "乌龙养血胶囊(松鹿)",
                "title": "补气益血，活血通络，快速清除血液中的有毒物质和血管内淤积脂质沉积物。",
                "price": "&yen;236"
              }, {
                "imgid": "12039",
                "name": "磷酸西格列汀片(捷诺维)",
                "title": "单药治疗 本品配合饮食控制和运动，用于改善2 型糖尿病患者的血糖控制。 与二甲双胍联用 当单独使用盐酸二甲双胍血糖控制不佳时,可与盐酸二甲双胍联合使用，在饮食和运动基础上改善2 型糖尿病患者的血糖控制。本品单药或与二甲双胍联合治疗的推荐剂量为100 mg，每日一次。本品可与或不与食物同服。 肾功能不全的患者 轻度肾功能不全患者（肌酐清除率 [CrCl] ≥ 50 mL/min，相应的血清肌酐水平大约为男性≤ 1.7 mg/dL 和女性≤ 1.5 mg/dL）服用本品时，不需要调整剂量。 (详见包装内部说明书)",
                "price": "&yen;115"
              }, {
                "imgid": "326832",
                "name": "医诺速溶叶黄素酯粉(原叶黄素酯微囊粉)",
                "title": "高效补充人眼视网膜黄斑色素。",
                "price": "&yen;288"
              }, {
                "imgid": "158231",
                "name":  "妥塞敏 氨甲环酸片20片*5盒",
                "title": "用于黄褐斑，各种出血。",
                "price": "&yen;230"
              }, {
                "imgid": "438386",
                "name": "仙藜口服液(金马)",
                "title": "补气养血，宁心安神，健脾益肾。",
                "price": "&yen;58"
              }, {
                "imgid": "12046",
                "name": "吡硫翁锌气雾剂(适今可)",
                "title": "用于各种牛皮癣。",
                "price": "&yen;239"
              }, {
                "imgid": "12022",
                "name": "异维A酸软胶囊(泰尔丝)。",
                "title": "用于重度痤疮。",
                "price": "&yen;114"
              }, {
                "imgid": "11901",
                "name": "奥氮平片(欧兰宁)",
                "title": "奥氮平用于治疗精神分裂症。初始治疗有效的患者，奥氮平在维持治疗期间能够保持基临床效果。奥氮平用于治疗、重度躁狂发作。对奥氮平治疗有效的躁狂发作患者，奥氮平可用于预防双相情感障碍的复发。",
                "price": "&yen;106"
              }, {
                "imgid": "12005",
                "name": "奥卡西平片(曲莱)",
                "title": "本品适用于治疗原发性全面性强直-阵挛发作和部分性发作，伴有或不伴有继发性全面性发作。 本品适用于成年人和5岁以及5岁以上儿童。",
                "price": "&yen;185"
              }, {
                "imgid": "47100",
                "name": "鸿茅药酒",
                "title": "祛风除湿，补气通络，舒筋活血，健脾温肾。用于风寒湿痹，筋骨疼痛，脾胃虚寒，肾亏腰酸以及妇女气虚血亏。",
                "price": "&yen;268"
              }, {
                "imgid": "339627",
                "name": "舒筋健腰丸OTC(白云山)",
                "title": "补益肝肾，强健筋骨，驱风除湿，活络止痛。用于腰膝酸痛。",
                "price": "&yen;790"
              }, {
                "imgid": "12409",
                "name": "槐耳颗粒(金克)",
                "title": "扶正固本，活血消症。适用于正气虚弱，瘀血阻滞，原发性肝癌不宜手术和化疗者辅助治疗用药，有改善肝区疼痛、腹胀、乏力等症状的作用。在标准的化学药品抗癌治疗的基础上，可用于肺癌、胃肠癌、乳腺癌所致的神疲乏力、少气懒言、脘腹疼痛或胀闷、纳谷少馨、大便干结或溏泄、或气促、咳嗽、多痰、面色晄白、胸胁不适等症，改善患者生活质量。",
                "price": "&yen;135"
              }, {
                "imgid": "11842",
                "name": "肠内营养粉剂(TP)(安素)",
                "title": "可作为全营养支持或部分营养补充，适用于成人及四岁或四岁以上的儿童．可口服或管饲。",
                "price": "&yen;62"
              }, {
                "imgid": "7474",
                "name": "沙美特罗替卡松粉吸入剂(舒利迭)",
                "title": "舒利迭以联合用药形式，用于可逆性阻塞性气道疾病的常规治疗，包括成人和儿童哮喘。",
                "price": "&yen;217"
              }, {
                "imgid": "70477",
                "name": "布地奈德福莫特罗粉吸入剂(信必可都保)",
                "title": "1.哮喘：本品适用于需要联合应用吸入皮质激素和长效β2一受体激动剂的哮喘病人的常规治疗，吸入皮质激素和“按需”使用短效β2一受体激动剂不能很好地控制症状的患者，或应用吸入皮质激素和长效β2一受体激动剂，症状已得到良好控制的患者。 2.慢性阻塞性肺病（COPD）：针对患有COPD(FEV1≤预计正常值的50%)和伴有病情反复发作恶化的患者进行对症治疗，这些患者尽管长期规范的使用长效的支气管扩张剂进行治疗，仍会出现明显的临床症状。",
                "price": "&yen;225"
              }, {
                "imgid": "961",
                "name": "苄达赖氨酸滴眼液(莎普爱思)",
                "title": "早期老年性白内障。",
                "price": "&yen;36"
              }, {
                "imgid": "3041",
                "name": "复方鳖甲软肝片(回乐)",
                "title": "软坚散结，化瘀解毒，益气养血。用于慢性乙型肝炎肝纤维化，以及早期肝硬化属瘀血阻络、气血亏虚兼热毒未尽证。症见：胁肋隐痛或胁下痞块，面色晦暗．脘腹胀满，纳差便溏，神疲乏力，口干且苦，赤缕红丝等。",
                "price": "&yen;80"
              }, {
                "imgid": "7047",
                "name": "恩替卡韦片(博路定)",
                "title": "本品适用于病毒复制活跃，血清转氨酶ALT持续升高或肝脏组织学显示有活动性病变的慢性成人乙型肝炎的治疗。",
                "price": "&yen;202"
              }, {
                "imgid": "13645",
                "name": "欧姆龙电子血压计HEM-8102A(上臂式)",
                "title": "简单准确测量血压。",
                "price": "&yen;158"
              }, {
                "imgid": "219269",
                "name": "强生-稳豪倍易血糖仪",
                "title": "强生稳豪倍易血糖仪ONETOUCH Ult",
                "price": "&yen;338"
              }, {
                "imgid": "637387",
                "name": "多通葆汉森元牌汉森元粉",
                "title": "增强免疫力，调节肠道菌群。",
                "price": "&yen;458"
              }

            ]
          }
          var prolist = eval(listpro.mlist)
          $(".jk-m-load").show(0, function() {
            self.loadMore(prolist);
            if (prolist.length - 1 < i) {
              $(".jk-m-load").hide();
            }
          })
        } else if ($(window).scrollTop() < defTop) {
          defTop = $(window).scrollTop();
        }
      }
    })
  }
}
$(function() {
  var feedback = {
    init: function() {
      var self = this;
      var close = $(".close");
      var userfeed = $(".user-feedback");
      var obj = $(".jk-user-feedback");
      var allBg = $(".jk-cover-bg");
      self.hideWin(obj, close, userfeed, allBg);
    },
    hideWin: function(obj, btn, ufeed, bg) {
      ufeed.on("click", function() {
        bg.show(0, function() {
          obj.removeClass("fadeOutDown").addClass("animated fadeInDown").show();
        })
      })
      btn.on("click", function() {
        bg.hide(0, function() {
          obj.removeClass("fadeInDown").addClass("fadeOutDown");
        })

      })
      $(".suggest").on("click", function() {
        var vSuggestContent = $("#txtaSuggest").val();
        if ($.trim(vSuggestContent) == "") {
          alert("请填写内容！");
          return false;
        }
        var postdata = 'strContent=' + vSuggestContent;
        $.post("/ajax/advice", postdata, function(returnDate) {
          $("#txtaSuggest").val("");
          alert(returnDate);
          bg.hide(0,function(){
          obj.removeClass("fadeInDown").addClass("fadeOutDown");            
          })
        });
      })
    }
  }
  feedback.init();
  var search = {
    init: function() {
      var self = this;
      var log = $(".jk-logo");
      var input = $(".jk-search-text");
      var jkall = $("#jk-scroll");
      var bgcolor = $(".jk-search-box-cover");
      var button = $(".jk-login");
      var del_ico = $(".jk-search-del-icon");
      self.focus(input, jkall, log, bgcolor, button, del_ico);
      self.cancel(input, button, jkall, log, bgcolor, del_ico);
    },
    focus: function(obj, jk, logo, bg, btn, cut) {
      obj.focus(function() {
        sTop = $(window).scrollTop();
        login = $('#login').html();
        opt = bg.css("opacity");
        $(".bottom-to-top").hide();
        bg.css("opacity", 1);
        jk.hide();
        $("body").removeClass("hide-landing").addClass("show-landing");
        logo.hide(0, function() {
          $(this).next().addClass("no-lefgmag");
          btn.find("a").attr("href", "javascript:;").removeClass("login-state").addClass("cancel").text("取消");
        })
        $(this).keyup(function() {
          if ($.trim($(this).val()) != "") {
            cut.show(0, function() {
              btn.find("a").removeClass("cancel").addClass("search").text("搜索");
              $(".search_land_wrap").show();
            });
          } else {
            cut.hide(0, function() {
              $(".search_land_wrap").hide();
              btn.find("a").removeClass("search").addClass("cancel").text("取消");
            });

          }
        })
      })
    },
    cancel: function(obj, btn, jk, logo, bg, cut) {
      btn.on("click", ".cancel", function() {

        logo.show(100, function() {
          $(this).next().removeClass("no-lefgmag");
          bg.css("opacity", opt);
          jk.show();
          window.scrollTo(0, sTop);
          $("body").removeClass("show-landing").addClass("hide-landing");
          $('#login').html(login)
        })
      });
      btn.on("click", ".search", function() {
        SearchSubmit(obj.val(), event)
      });
      cut.click(function() {
        $(this).hide(0, function() {
          obj.val("");
          $(".search_land_wrap").hide();
          btn.find("a").removeClass("search").addClass("cancel").text("取消");
        })
      })
    }
  };
  $(window).scroll(function() {
    var top = $(window).scrollTop();
    var top2 = $(".jk-nav").offset().top;
    var x = 0;
    if (top / top2 >= 0.85) {
      x = 0.85;
      $("#mhome-backtoTop").show()
    } else {
      x = top / top2;
      $("#mhome-backtoTop").hide();
    }
    $(".jk-search-box-cover").css("opacity", x);
    if ($(".jk-search-text").is(":focus")) {
      $(".jk-search-box-cover").css({
        "opacity": 1
      });
    };
  });
  search.init();

  (function($) {
    $.fn.picLazyLoad = function(settings) {
      var $this = $(this),
        _winScrollTop = 0,
        _winHeight = $(window).height();
      settings = $.extend({
        threshold: 0,
        placeholder: ''
      }, settings || {});
      lazyLoadPic();
      $(window).on('scroll load', function() {
        _winScrollTop = $(window).scrollTop();
        lazyLoadPic();
      });

      function lazyLoadPic() {
        $this.each(function() {
          var $self = $(this);
          if ($self.is('img')) {
            if ($self.attr('data-original')) {
              var _offsetTop = $self.offset().top;
              if ((_offsetTop - settings.threshold) <= (_winHeight + _winScrollTop)) {
                $self.attr('src', $self.attr('data-original'));
                $self.removeAttr('data-original');
              }
            }
          } else {
            if ($self.attr('data-original')) {
              if ($self.css('background-image') == 'none') {
                $self.css('background-image', 'url(' + settings.placeholder + ')');
              }
              var _offsetTop = $self.offset().top;
              if ((_offsetTop - settings.threshold) <= (_winHeight + _winScrollTop)) {
                $self.css('background-image', 'url(' + $self.attr('data-original') + ')');
                $self.removeAttr('data-original');
              }
            }
          }
        });
      }
    }
  })($);
  $('img').picLazyLoad();
  Load.init();
})